package com.epoint.mobileoa.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.ui.todolist.ProgressTaskDealView;

/**
 * 
 * @author lilin
 * @date 2011-11-13 下午09:12:51
 * @ClassName: 意见模版适配器
 */
public class OpitionTemplateAdp extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<Map<String, Object>> mData;
	public static Map<Integer, Boolean> isSelected;

	public OpitionTemplateAdp(ProgressTaskDealView context,
			List<Map<String, Object>> mData1) {
		mData = mData1;
		mInflater = LayoutInflater.from(context);

		// 这儿定义isSelected这个map是记录每个listitem的状态，初始状态全部为false。
		isSelected = new HashMap<Integer, Boolean>();
		for (int i = 0; i < mData.size(); i++) {
			isSelected.put(i, false);
		}
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		// convertView为null的时候初始化convertView。
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.listitem_opinion, null);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.cBox = (CheckBox) convertView.findViewById(R.id.cb);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.title.setText(mData.get(position).get("title").toString());
		holder.cBox.setChecked(isSelected.get(position));
		return convertView;
	}

	public final class ViewHolder {
		public TextView title;
		public CheckBox cBox;
	}
}
